package com.dyh.quickdemo.bizDemo.PlatformSplit;

import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.assertj.core.util.Lists;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/*
@Author=Joey Wheeler
@Date=2020/11/25 17:11
*/
@Slf4j
@Setter@Getter
public class M1 {

    List<String> all;
    List<List<String>> result = new ArrayList<>();

    public static M1 with(List<String> all){
        M1 m1 =new M1();
        m1.setAll(new ArrayList<>(all));
        return m1;
    }

    public  M1 bundle(String... ele){
        this.result.add(Arrays.asList(ele));
        this.all.removeAll(Arrays.asList(ele));
        return this;
    }

    public List<List<String>> group(){
        this.result.add(all);
        return this.result;
    }

//    public M1(List<String> all){
//        this.all = new ArrayList<>(all);
//    }

    List<List<String>> split(List<String>... groups){
        List<List<String>> res = new ArrayList<>();
        List<String> temp = new ArrayList<>(all);
        for (List<String> group : groups) {
            res.add(group);
            temp.removeAll(group);
        }
        res.add(temp);
        return res;
    }



    @Test
    public void test(){
//        List<List<String>> res = split(
//                Lists.newArrayList("taobao"),
//                Lists.newArrayList("pinduoduo"),
//                Lists.newArrayList("dyh","alibaba")
//                );
       List<List<String>>res =  M1.with(Lists.newArrayList("TAOBAO","PINDUODUO",
                "hgc","sfg","DYH","ALIBABA"))
                .bundle("TAOBAO")
                .bundle("PINDUODUO")
                .bundle("ALIBABA")
                .bundle("DYH")
                .group();

        for (int i =0;i<res.size();i++){
            log.info("i={} res={}",i,JSON.toJSONString( res.get(i)));
        }
    }
}
